home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / IIGS / TN.IIGS.057 < prev    next >
Encoding:
Text File  |  1991-11-15  |  3.9 KB  |  90 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. Apple IIGS
  8. #57:    Preventing Memory Compacting and Purging
  9.  
  10. Revised by:    Dave "nocturnal" Lyons                           December 1991
  11. Written by:    Dave Lyons                                           July 1989
  12.  
  13. This Technical Note discusses how you can use the Memory Manager from
  14. interrupt routines and documents a flag byte that debugging utilities can use 
  15. to temporarily prevent the Memory Manager from moving or purging memory.
  16. Changes since July 1989:  Expanded and retitled Note to discuss safe use 
  17. of the Memory Manager at interrupt time.
  18. _____________________________________________________________________________
  19.  
  20. The Memory Manager does not disable interrupts while it's busy.  Instead, it
  21. increments the system BUSY flag when it's in the middle of something 
  22. important.
  23.  
  24.  
  25. Can interrupt routines call the Memory Manager?
  26.  
  27. If you write code that executes at interrupt time, you must check the BUSY 
  28. flag (the byte at $E100FF) before making any Memory Manager calls.  If the 
  29. BUSY flag is zero, it's safe to call the Memory Manager.  If the BUSY flag is 
  30. nonzero, the Memory Manager may be in the middle of a call, so it is not safe 
  31. to call it.
  32.  
  33. What routines must check the BUSY flag?
  34.  
  35. Classic desk accessory main routines and shutdown routines do not need to 
  36. check the BUSY flag.  If the Event Manager is active, the CDA gets control 
  37. during GetNextEvent, not at interrupt time.  If the Event Manager is not 
  38. active, the CDA gets control only when the BUSY flag reaches zero.
  39.  
  40. GS/OS signal handlers do not need to check the BUSY flag, because the system 
  41. dispatches signals only when the BUSY flag is zero.
  42.  
  43. Run Queue tasks do not need to check the BUSY flag before calling the Memory 
  44. Manager. The system dispatches Run Queue tasks at SystemTask time--the BUSY 
  45. flag may not be zero, but no Memory Manager call will be in progress.
  46.  
  47. Heartbeat interrupt tasks and other interrupt handlers do need to check the 
  48. BUSY flag before calling the Memory Manager.
  49.  
  50. Interrupt-time use of moveable memory blocks
  51.  
  52. If an interrupt-time routine needs access to an unlocked, non-fixed memory 
  53. block, you must check the BUSY flag.  It is not sufficient to lock the block, 
  54. use it, and then unlock it (even if you twiddle the handle's access word 
  55. directly).  If the BUSY flag is non-zero, the Memory Manager could be in the 
  56. middle of compacting memory, which means your block could be "in transit" from 
  57. one address to another (some bytes copied, some not).
  58.  
  59. To use already-allocated memory at interrupt time, either keep the block 
  60. locked or fixed, or check that the BUSY flag is zero before using the memory 
  61. at interrupt time.
  62.  
  63. What if BUSY is nonzero?
  64.  
  65. If the BUSY flag is nonzero, you may want to (depending on your application) 
  66. exit the interrupt routine and hope the BUSY flag is zero the next time, or 
  67. call SchAddTask in the Scheduler to make the system call your routine when the 
  68. BUSY flag next returns to zero.  Keep in mind, though, that only four 
  69. scheduled tasks can be pending at a time.
  70.  
  71.  
  72. Interrupt-time flag byte
  73.  
  74. If the byte at location $E100CB is non-zero, the Memory Manager will not move 
  75. any memory blocks, and it will not purge any blocks while trying to allocate 
  76. memory (PurgeHandle and PurgeAll will still purge blocks).
  77.  
  78. Debugging utilities may temporarily increment this byte to allocate memory in 
  79. situations when it is not safe for existing memory blocks to be moved or 
  80. purged.
  81.  
  82. This flag byte is for use only by debugging aids and System Software.  It 
  83. would be mind-numbingly stupid for an application to use this flag instead of 
  84. using HLock and HUnlock, since the advantages of a Memory Manager architecture 
  85. with relocatable blocks would be lost.
  86.  
  87. It is not useful to check the value of the $E100CB flag.  It is always set 
  88. during interrupt handling whether any non-reentrant system component is busy 
  89. or not.
  90.